package com.example.demo.Service.Impl;

import com.example.demo.Dao.VendorDetailMapper;
import com.example.demo.Dao.VendorMapper;
import com.example.demo.Entity.Customer;
import com.example.demo.Entity.Vendor;
import com.example.demo.Entity.VendorDetail;
import com.example.demo.Param.UserInsertParam;
import com.example.demo.Param.VendorInsertParam;
import com.example.demo.Param.VendorUpdateParam;
import com.example.demo.Service.VendorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VendorServiceImpl implements VendorService {

    @Autowired
    private VendorMapper vendorMapper;


    @Override
    public List<Vendor> getAll() {
        List<Vendor> vendors = vendorMapper.selectAll();
        return vendors;
    }

    @Override
    public void deleteVendor(Long id) {
        vendorMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateVendor(String vendorname, Long id) {

    }

    @Override
    public Vendor createOne(VendorInsertParam vendorInsertParam) {
        Vendor vendor = new Vendor();
        vendor.setVendorname(vendorInsertParam.getVendorname());
        vendor.setVendortel(vendorInsertParam.getVendortel());
        vendor.setVendoraddress(vendorInsertParam.getVendoraddress());
        vendorMapper.insert(vendor);
        return vendor;
    }

    @Override
    public void updateVendor(VendorUpdateParam vendorUpdateParam) {
        Vendor vendor = new Vendor();
        vendor.setId(vendorUpdateParam.getId());
        vendor.setVendorname(vendorUpdateParam.getVendorname());
        vendor.setVendortel(vendorUpdateParam.getVendortel());
        vendor.setVendoraddress(vendorUpdateParam.getVendoraddress());
        vendorMapper.updateByPrimaryKey(vendor);
    }

    @Override
    public List<Vendor> searchVendor(String vendorname) {
        return vendorMapper.selectByVendorName(vendorname);
    }
}
